package com.yun.algorithmproblem.leetcode;

public class Leetcode2419 {

    public static void main(String[] args) {
        int[] nums = {323376, 323376, 323376, 323376, 323376, 323376, 323376, 75940, 75940};
        Leetcode2419 obj = new Leetcode2419();
        System.out.println(obj.longestSubarray(nums));
    }


    public int longestSubarray(int[] nums) {
        int ans = 0;
        int mx = 0;
        int cnt = 0;
        for (int x : nums) {
            if (x > mx) {
                // 发现新的 mx，重新统计所有内容
                mx = x;
                cnt = 1;
                ans = 1;
            } else if (x == mx) {
                cnt++;
                ans = Math.max(ans, cnt);
            } else {
                cnt = 0; // 连续 mx 断开了，重新统计
            }
        }
        return ans;
    }
}
